home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 282_01 / quipupdt.c < prev    next >
Text File  |  1989-01-11  |  2KB  |  80 lines

  1. /*
  2. HEADER:        ;
  3. TITLE:         QUIP;
  4. VERSION:       2.0;
  5. DESCRIPTION:   "Part of a fortune cookie system
  6.              
  7.                This program takes the quip file 'quip.dat' and creates an new
  8.                index file 'quip.key' from it.";
  9. KEYWORDS:      quip, fortune, utility, startup;
  10. SYSTEM:        MS-DOS, UNIX;
  11. FILENAME:      quipupdt.c;
  12. WARNINGS:      "";
  13. SEE-ALSO:      QUIP.C, QUIP.H, QUPUPDT.C QUIPADD.C, QUIP.DAT, QUIP.KEY;
  14. AUTHORS:       ??;
  15. MODIFIED BY:   David Bryant;
  16. COMPILERS:     Microsoft Quick C;
  17. */
  18.  
  19. #include <stdio.h>
  20.  
  21. FILE  *seekfp,    /* the address file */
  22.       *quipfp;    /* the actual fortune file */
  23.  
  24. #include    "quip.h"
  25.  
  26. openfiles()
  27. {
  28.    seekfp = fopen(seekname, "wb");
  29.    if (seekfp == 0) {
  30.       puts("Cannot open address file.");
  31.       exit(0);
  32.    }
  33.    quipfp = fopen(quipname, "r");         /* Open as TEXT file */
  34.    if (quipfp == 0) {
  35.       puts("Cannot open quip data file.");
  36.       exit(0);
  37.    }
  38. }
  39.  
  40. putaddr(offset)
  41. long  offset;
  42. {
  43.    if (fwrite((char *)&offset, sizeof(long), 1, seekfp) != 1)
  44.       printf("write error on address file\n");
  45. }
  46.  
  47. int findquips()
  48. {
  49.    #define MAX_LINE  128                  /* Max line length */
  50.    int   count = 0;
  51.    char  line[MAX_LINE];
  52.  
  53.    putaddr(0L);
  54.    for (;;)
  55.       {
  56.       if (fgets(line, MAX_LINE, quipfp) == 0)
  57.          return count;
  58.       if (line[0] == SEPERATOR)
  59.          {
  60.          putaddr((long)ftell(quipfp));
  61.          count++;
  62.          }
  63.       }
  64. }
  65.  
  66. closefiles()
  67. {
  68.    fclose(seekfp);
  69.    fclose(quipfp);
  70. }
  71.  
  72. main()
  73. {
  74.    openfiles();
  75.    printf("Files open...\n");
  76.    printf("There were %d quips found.",findquips());
  77.    closefiles();
  78. }
  79.  
  80.